/*
 * @SuperTV All Rights Reserved
 */

package com.android.volley.toolbox;

import android.content.Context;
import android.content.pm.PackageInfo;

import com.android.volley.Network;
import com.android.volley.RequestQueue;

import java.io.File;

public class Volley {

    /** Default on-disk cache directory. */
    public static final String DEFAULT_CACHE_DIR = "volley";

    /**
     * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
     *
     * @param context A {@link Context} to use for creating the cache dir.
     * @param stack An {@link HttpStack} to use for the network, or null for default.
     * @return A started {@link RequestQueue} instance.
     */
    public static RequestQueue newRequestQueue(Context context, HttpStack stack, int poolSize, int queueType) {
        File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);

        try {
            String packageName = context.getPackageName();

            PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
        } catch (Exception e) {
        	e.printStackTrace();
        }

        if (stack == null) {
            stack = new HurlStack();
        }

        Network network = new BasicNetwork(stack);

        RequestQueue queue = new RequestQueue(context, new DiskBasedCache(cacheDir), network, poolSize, queueType);
        queue.start();

        return queue;
    }

    /**
     * Creates a default instance of the worker pool and calls {@link RequestQueue#start()} on it.
     *
     * @param context A {@link Context} to use for creating the cache dir.
     * @return A started {@link RequestQueue} instance.
     */
    public static RequestQueue newRequestQueue(Context context) {
        return newRequestQueue(context, null, RequestQueue.DEFAULT_NETWORK_THREAD_POOL_SIZE, RequestQueue.QUEUE_HTTP);
    }
    
    public static RequestQueue newRequestQueue(Context context, int poolSize) {
        return newRequestQueue(context, null, poolSize, RequestQueue.QUEUE_HTTP);
    }
    
    public static RequestQueue newRequestQueue(Context context, int poolSize, int queueType) {
        return newRequestQueue(context, null, poolSize, queueType);
    }
    
}
